var proCode=null;
var proName=null;
var proContact=null;
var proPhone=null;
var proAddress=null;
var proFax=null;
var proDesc=null;
var add=null;

$(function(){
	proCode=$("#proCode");
	proName=$("#proName");
	proContact=$("#proContact");
	proPhone=$("#proPhone");
	proAddress=$("#proAddress");
	proFax=$("#proFax");
	proDesc=$("#proDesc");
	add=$("#add");
	
	proCode.next().html("*");
	proName.next().html("*");
	proContact.next().html("*");
	proPhone.next().html(" *");
	proCode.bind("blur",function(){
     if(proCode.val()!=null&&proCode.val()!=""){
 		validateTip(proCode.next(),{"color":"green"},imgYes+"ok",true);

     }else{
  		validateTip(proCode.next(),{"color":"red"},imgNo+"供应商编码不能为空",false);

     }
		
	}).bind("focus",function(){
		validateTip(proCode.next(),{"color":"#666"},"* 请输入供应商编码",false);
	}).focus();
	proName.bind("blur",function(){
	     if(proName.val() != null && proName.val().length > 3 
					&& proName.val().length < 10){
	 		validateTip(proName.next(),{"color":"green"},imgYes+"ok",true);

	     }else{
	  		validateTip(proName.next(),{"color":"red"},imgNo+"供应商名称输入不规范，请重新输入",false);

	     }
			
		}).bind("focus",function(){
			validateTip(proName.next(),{"color":"#666"},"*用户名长度必须是大于3小于10的字符",false);
		});
	proContact.bind("blur",function(){
	     if(proContact.val() != null && proContact.val().length > 1 
					&& proContact.val().length <10){
	 		validateTip(proContact.next(),{"color":"green"},imgYes+"ok",true);

	     }else{
	  		validateTip(proContact.next(),{"color":"red"},imgNo+"联系输入不规范，请重新输入",false);

	     }
			
		}).bind("focus",function(){
			validateTip(proContact.next(),{"color":"#666"},"*联系人长度必须是大于2小于10的字符",false);
		});
	proPhone.bind("blur",function(){
	   var patrn=/^(13[0-9]|15[0-9]|18[0-9])\d{8}$/;
	   if(proPhone.val().match(patrn)){
			validateTip(proPhone.next(),{"color":"green"},imgYes+"ok",true);

	   }else{
			validateTip(proPhone.next(),{"color":"red"},imgNo+"你输入的手机号格式不正确",false);

	   }
	}).bind("focus",function(){
		validateTip(phone.next(),{"color":"#666666"},"* 请输入手机号",false);

	});

	add.bind("click",function(){
		if(proCode.attr("validateStatus")!="true"){
			proCode.blur();
		}else if(proName.attr("validateStatus")!="true"){
			proName.blur();	
		}else if(proContact.attr("validateStatus")!="true"){
			proContact.blur();	
		}else if(proPhone.attr("validateStatus")!="true"){
			proPhone.blur();	
		}else{
	      if(confirm("是否确认提交数据")){
	    	  $("#providerForm").submit();
	      }
	     }
	});
});
